import {
    getHomeCasual,
    getHomeNav,
    getHomeShopList,
    getRecommendShopList,
    getSearchGoods
} from '../api'
import {
    HOME_CASUAL,
    HOME_NAV,
    HOME_SHOP_LIST,
    RECOMMEND_SHOP_LIST,
    SEARCH_GOODS
} from './mutation-types';

export default {
    //获取首页轮播图
    async reqHomeCasual({ commit }) {
        const result = await getHomeCasual();
        commit(HOME_CASUAL, { homecasual: result.message })
    },

    //获取首页导航
    async reqHomeNav({ commit }) {
        const result = await getHomeNav();
        commit(HOME_NAV, { homenav: result.message.data })
    },

    //获取首页商品列表
    async reqHomeShopList({ commit }) {
        const result = await getHomeShopList();
        commit(HOME_SHOP_LIST, { homeshoplist: result.message.goods_list })
    },

    //获取推荐商品列表
    async reqRecommendShopList({ commit }, params) {
        const result = await getRecommendShopList(params);
        commit(RECOMMEND_SHOP_LIST, { recommendshoplist: result.message });
        params.callback && params.callback();
    },

    //获取搜索数据列表
    async reqSearchGoods({ commit }) {
        const result = await getSearchGoods();
        commit(SEARCH_GOODS, { searchgoods: result.message.data })
    }

}